﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/1/2009
 * Time: 9:48 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using NHibernate;
using System.Collections.Generic;
using System.Data;
using Buaya.Model.Dao.Interface;

namespace Buaya.Model.Dao.NHibernate
{
	/// <summary>
	/// Description of NHibernateEmployeeDao.
	/// </summary>
	public class NHibernateEmployeeDao : IEmployeeDao
	{
		public NHibernateEmployeeDao()
		{
		}
		
		public void SaveOrUpdate(Employee employee)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.SaveOrUpdate(employee);
			session.Flush();
		}
		
		public void Delete(Employee employee)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.Delete(employee);
			session.Flush();
		}
		
		public Employee ReadByPk(int id)
		{
			return NHibernateHelper.OpenSession().Load<Employee>(id);
		}
		
		public Employee ReadById(string id)
		{
			IQuery query = NHibernateHelper.OpenSession().CreateQuery("from Employee where IDNo = :no");
			query.SetString("no", id);
			return query.UniqueResult<Employee>();
		}
		
		public IList<Employee> FindAll()
		{
			return NHibernateHelper.OpenSession().CreateCriteria(typeof(Employee)).List<Employee>();
		}
		
		public DataSet FindAllDS()
		{
			throw new NotImplementedException();
		}
	}
}
